<template>
  <div>
    <!-- 面包屑 -->
    <Headline
      :headline1="$t('m.PersonnelAdmin') + '  /  '"
      :headline2="$t('m.StaffInfo')"
    ></Headline>
    <!-- 搜索和表单部分 -->
    <a-card style="width: 100%">
      <div class="search">
        <div class="search-a ov_flex">
          <a-select
            class="select-a"
            v-model="formlists.status"
            @change="handleSelectChange"
          >
            <a-select-option value="-1"> 全部 </a-select-option>
            <a-select-option value="1"> 有效 </a-select-option>
            <a-select-option value="0"> 无效 </a-select-option>
          </a-select>
          <a-input-search
            placeholder="请输入搜索内容"
            v-model="formlists.key"
            size="large"
            @search="pupSearch"
          />
        </div>
        <a-tree-select
          v-model="value"
          show-search
          style="width: 30%; height: 35px; margin-left: 30px"
          :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
          placeholder="Please select"
          allow-clear
          @change="checked"
          tree-default-expand-all
        >
          <a-tree-select-node
            v-for="item in items"
            :key="item.ymorgtreecode"
            :cont="item"
            :value="item.custorgname"
            :title="item.custorgname"
          >
            <a-tree-select-node
              v-for="int in item.children"
              :key="int.ymorgtreecode"
              :cont="int"
              :value="int.custorgname"
              :title="int.custorgname"
            >
              <a-tree-select-node
                v-for="ins in int.children"
                :key="ins.ymorgtreecode"
                :cont="ins"
                :value="ins.custorgname"
                :title="ins.custorgname"
              />
            </a-tree-select-node>
          </a-tree-select-node>
        </a-tree-select>
        <div class="btns">
          <a-button
            @click="addRess"
            type="primary"
            v-if="isTrue('personnel:staff:add')"
            style="width: 80px; height: 35px; font-size: 13px;margin-left: 15px;"
          >
            {{ $t("m.NewStaff") }}
          </a-button>
          <a-button
            type="primary"
            :disabled="!isTrue('personnel:staff:import')"
            @click="importEdit()"
            style="
              width: 80px;
              height: 35px;
              margin-left: 15px;
              font-size: 13px;
            "
            >{{ $t("m.TheImportFile") }}</a-button
          >
          <a-button
            type="primary"
            style="
              width: 80px;
              height: 35px;
              margin-left: 15px;
              font-size: 13px;
            "
            :disabled="!isTrue('personnel:staff:export')"
            @click="exportEdit()"
            >{{ $t("m.TheExportFile") }}</a-button
          >
        </div>
        <div class="chend">
          <a-checkbox :defaultChecked="formlists.vChild" @change="textChange">
            {{ $t("m.WhetherToDisplayChildNodes") }}
          </a-checkbox>
        </div>
      </div>
      <div class="conter-table">
        <div id="components-table-demo-size">
          <a-table
            :rowKey="(record) => record.id"
            :columns="columns"
            :data-source="datas"
            bordered
            :pagination="false"
          >
            <div slot="chxeds" slot-scope="chxeds, doc, i">
              <a-switch
                default-checked
                :disabled="!isTrue('personnel:staff:valid')"
                :checked="doc.status == 0 ? false : true"
                @change="chxedsd(chxeds, doc, i)"
              />
            </div>
            <div slot="tags" slot-scope="text, tags, i">
              <a-button
                class="btn"
                :disabled="!isTrue('personnel:staff:update')"
                type="primary"
                icon="diff"
                @click="changed(text, tags, i)"
                >{{ $t("m.Modification") }}</a-button
              >
              <a-button
                class="btn"
                type="danger"
                icon="delete"
                @click="pupildelete(text, tags, i)"
                >{{ $t("m.Delete") }}</a-button
              >

              <a-button
                class="btn"
                :disabled="!isTrue('personnel:staff:change')"
                type="primary"
                @click="eadjustment(text, tags, i)"
                >{{ $t("m.AdjustTheClassCluster") }}</a-button
              >
            </div>
          </a-table>
          <a-pagination
            class="pages"
            show-size-changer
            :defaultPageSize="5"
            :default-current="1"
            :total="total"
            @change="upilPages"
            :pageSizeOptions="['5', '10', '30', '40']"
            @showSizeChange="onShowupilChange"
          />
        </div>
      </div>
    </a-card>
    <!-- 添加弹窗 -->
    <Modal :modal="modals" @modalLast="editLodemo" @modalhand="modalhand">
      <a-form-model
        class="set-time"
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-form-item :label="$t('m.Thevaluedate')">
          <a-date-picker v-model="form.startDate" @change="DateonChangeA" />
        </a-form-item>
        <a-form-item :label="$t('m.Departuredate')">
          <a-date-picker v-model="form.endDate" @change="DateonChangeB" />
        </a-form-item>
        <a-form-model-item
          :label="$t('m.jobnumber')"
          ref="staffOrStuCode"
          prop="staffOrStuCode"
        >
          <a-input v-model="form.staffOrStuCode" />
        </a-form-model-item>
        <a-form-model-item
          :label="$t('m.Name')"
          ref="staffOrStuName"
          prop="staffOrStuName"
        >
          <a-input v-model="form.staffOrStuName" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.CellPhoneNumber')">
          <a-input :maxLength="11" v-model="form.mobile" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.Sex')" prop="sex">
          <a-radio-group v-model="form.sex">
            <a-radio value="1"> 男 </a-radio>
            <a-radio value="2"> 女 </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item :label="$t('m.Nation')">
          <a-input v-model="form.nation" />
        </a-form-model-item>
        <a-form-item :label="$t('m.Birthday')">
          <a-date-picker v-model="form.birthday" @change="DateonChangeC" />
        </a-form-item>
        <a-form-model-item :label="$t('m.IdentityCard')">
          <a-input v-model="form.idCard" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.Address')">
          <a-input v-model="form.address" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.CardNumber')">
          <a-input v-model="form.cardNo"  :disabled="disableds" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.Password')">
          <a-input v-model="form.passPassword" />
        </a-form-model-item>
        <a-form-model-item :label="$t('m.NatureOfPersonnel')" prop="property">
          <a-select v-model="form.property">
            <a-select-option
              v-for="item in dictionariesB"
              :value="item.code"
              :key="item.code"
            >
              {{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="email">
          <a-input v-model="form.email" />
        </a-form-model-item>
      </a-form-model>
      <a-table
        :columns="linkcolumn"
        :dataSource="form.contacts"
        :pagination="false"
        :rowKey="(r, i) => i"
        bordered
      >
        <template slot="title"> {{ $t("m.ContactInformation") }} </template>
        <div slot="equipment" slot-scope="text, tags, i" v-if="tags.isNew">
          <a-input v-model="form.contacts[i].linkman" />
        </div>
        <div slot="equipment" slot-scope="text, tags, i" v-else>
          <div>{{ form.contacts[i].linkman }}</div>
        </div>

        <div slot="enter" slot-scope="text, tags, i" v-if="tags.isNew">
          <a-input :maxLength="11" v-model="form.contacts[i].linkmobile" />
        </div>
        <div slot="enter" slot-scope="text, tags, i" v-else>
          <div>{{ form.contacts[i].linkmobile }}</div>
        </div>
        <div slot="readt" slot-scope="text, tags, i" v-if="tags.isNew">
          <a-select
            class="select-a select-b"
            v-model="form.contacts[i].linkdes"
          >
            <a-select-option
              v-for="item in dictionariesA"
              :value="item.name"
              :key="item.name"
              >{{ item.name }}</a-select-option
            >
          </a-select>
        </div>
        <div slot="readt" slot-scope="text, tags" v-else>
          <!-- <div>{{tags.inoutname}}</div> -->
          <div v-for="item in dictionariesA" :key="item.name">
            <div v-if="tags.linkdes == item.name">{{ item.name }}</div>
          </div>
        </div>
        <div slot="tags" slot-scope="text, tags, i" v-if="tags.isNew">
          <a-button
            class="btn"
            type="primary"
            icon="diff"
            @click="contvmo(text, tags, i)"
            >{{ $t("m.Save") }}</a-button
          >
        </div>
        <div slot="tags" slot-scope="text, tags, i" v-else>
          <a-button
            class="btn"
            type="primary"
            icon="diff"
            @click="contvmos(text, tags, i)"
            >{{ $t("m.Modification") }}</a-button
          >
          <a-button
            class="btn"
            type="danger"
            icon="diff"
            @click="deletevmos(text, tags, i)"
            >{{ $t("m.Delete") }}</a-button
          >
        </div>
      </a-table>
      <a-button
        style="width: 100%; margin-top: 16px; margin-bottom: 8px"
        type="dashed"
        icon="plus"
        @click="newMember"
        >{{ $t("m.Addingcontacts") }}</a-button
      >
    </Modal>
    <Delete ref="unpdelete" :dalete="dalete" @confirm="unpdelete"></Delete>
    <Delete
      ref="unpchxed"
      :dalete="unpdalete"
      @confirm="unpchxed"
      :title="title"
    ></Delete>
    <!-- 调整档案弹窗 -->
    <Modal :modal="eadjust" @modalLast="eadjustup" @modalhand="eadjusthand">
      <a-tree :tree-data="items" @select="selectlist">
        <template #title="{ key: treeKey, custorgname }">
          <a-dropdown :trigger="['contextmenu']">
            <span>{{ custorgname }}</span>
            <template #overlay>
              <a-menu
                @click="({ key: id }) => onContextMenuClick(treeKey, menuKey)"
              >
                <a-menu-item key="1">1st menu item</a-menu-item>
                <a-menu-item key="2">2nd menu item</a-menu-item>
                <a-menu-item key="3">3rd menu item</a-menu-item>
              </a-menu>
            </template>
          </a-dropdown>
        </template>
      </a-tree>
    </Modal>
    <!-- 导入档案弹窗 -->
    <Modal :modal="imports" @modalLast="importsup" @modalhand="importshand">
      <a-form-model-item :label="$t('m.ImportExcel')" class="form-modak">
        <a-input style="width: 150px" v-model="filex"></a-input>
        <a-upload
          ref="upload"
          name="file"
          :before-upload="beforeUpload"
          :showUploadList="false"
          :customRequest="cover"
        >
          <a-button type="primary">{{ $t("m.ImportExcel") }}</a-button>
        </a-upload>
      </a-form-model-item>
      <div class="mobles">
      <p>1.上传文件必须为Excel,扩展名为.xls或者xlsx</p>
      <p>2.若导入修改请直接在导出人员信息的文件中修改</p>
      <p>3.信息填写规则请仔细查看模板的填写须知</p>
      <p class="flexs">
        4.导入添加模板
        <a-button
          @click="addexcel"
          type="primary"
          style="width: 20%; height: 32px;margin-left:15px;"
        >
          {{ $t("m.Downloadthetemplate") }}
        </a-button>
      </p>
    </div>
    </Modal>
  </div>
</template>

<script>
import XLSX from "xlsx";
import Headline from "@/components/Headline";
import Modal from "@/components/common/Modal";
import Laber from "@/components/common/Laber";
import Delete from "@/components/Delete";
import {
  getPerages,
  getStaff,
  getStudInfo,
  getDisabled,
  getSaveStudent,
  getDelStudentInfo,
  getMoveStaffInfo,
  getExportExcelTemplate,
  exportInfo,
  importInfo,
  getCustContactsList,
  delCustContacts,
} from "../../../api/perAges";
import { Setperms } from "@/assets/js/setperms";
import axios from "axios";
import { getdiction } from "@/api/dictionaries";
export default {
  name: "Perpupil",
  components: { Headline, Modal, Laber, Delete },
  data() {
    return {
      disableds: false,
      title: this.$t("m.AreYouSureAboutTheModificationStatus"),
      checkeds: false,
      //弹窗配置
      modal: {
        visible: false,
        width: "900px",
        title: this.$t("m.ModifyEmployeeInformation"),
      },
      modals: {
        visible: false,
        width: "900px",
        title: this.$t("m.NewEmployeeInformation"),
      },
      eadjust: {
        visible: false,
        width: "500px",
        title: this.$t("m.AdjustTheClass"),
      },
      imports: {
        visible: false,
        width: "500px",
      },
      dalete: {
        titles: this.$t("m.DeleteThePrompt"),
        type: "exclamation-point",
        text: this.$t("m.AreYouSureToDeleteThisData"),
      },
      unpdalete: {
        titles: this.$t("m.ChangeStatus"),
        type: "exclamation-point",
        text: this.$t("m.AreYouSureAboutTheModificationStatus"),
      },
      forpupdata: {
        orgType: 1,
        key: "",
      },
      deleteId: 0, //删除人员id
      value: "",
      items: [],
      rules: {
        staffOrStuCode: [
          {
            required: true,
            message: this.$t("m.RulesMessage"),
            trigger: "blur",
          },
          {
            min: 1,
            max: 18,
            message: this.$t("m.RulesNameMessage"),
            trigger: "blur",
          },
        ],
        staffOrStuName: [
          {
            required: true,
            message: this.$t("m.RulesMessage"),
            trigger: "blur",
          },
        ],
        sex: [
          {
            required: true,
            message: this.$t("m.RulesMessage"),
            trigger: "blur",
          },
        ],
        property: [
          {
            required: true,
            message: this.$t("m.RulesMessage"),
            trigger: "blur",
          },
        ],
      },
      columns: [
        {
          title: this.$t("m.jobnumber"),
          dataIndex: "stafforstucode",
        },
        {
          title: this.$t("m.Name"),
          dataIndex: "stafforstuname",
        },
        {
          title: this.$t("m.Sex"),
          dataIndex: "sex",
        },
        {
          title: this.$t("m.CellPhoneNumber"),
          dataIndex: "mobile",
        },
        {
          title: this.$t("m.IdentityCard"),
          dataIndex: "idcard",
          customRender: function (text) {
            var strcards = text.replace(/^(.{4})(?:\d+)(.{4})$/, "$1******$2");
            return strcards;
          },
        },
        {
          title: this.$t("m.CardNumber"),
          dataIndex: "cardno",
        },

        {
          title: this.$t("m.department"),
          dataIndex: "orgname",
        },
        {
          title: this.$t("m.Vaild"),
          key: "chxeds",
          dataIndex: "status",
          scopedSlots: { customRender: "chxeds" },
        },
        {
          title: this.$t("m.Operation"),
          key: "tags",
          dataIndex: "address",
          scopedSlots: { customRender: "tags" },
        },
      ],
      linkcolumn: [
        {
          title: this.$t("m.Name"),
          key: "equipment",
          dataIndex: "linkman",
          scopedSlots: { customRender: "equipment" },
        },
        {
          title: this.$t("m.Contactphone"),
          key: "enter",
          dataIndex: "linkmobile",
          scopedSlots: { customRender: "enter" },
        },
        {
          title: this.$t("m.RelationshipWithMyself"),
          key: "readt",
          dataIndex: "linkdes",
          scopedSlots: { customRender: "readt" },
        },
        {
          title: this.$t("m.Operation"),
          key: "tags",
          dataIndex: "address",
          scopedSlots: { customRender: "tags" },
        },
      ],
      fromdic: {
        groupcode: "SYS0000021",
        // insertall: "0|全部",
        where: "code<> -1 and code <> -100",
      },
      fromdicB: {
        groupcode: "SYS0000055",
        insertall: "",
        where: "attr1 = 1",
      },
      datas: [],
      form: {
        id: 0,
        ymOrgId: 0, //组织id
        infoType: 1, //人员类型
        staffOrStuCode: "", //人员编号
        staffOrStuName: "", //人员名称
        sex: "1", //性别
        nation: "", //民族
        birthday: "", //生日
        address: "", //地址
        startDate: "", //开始地址
        endDate: "", //结束日期
        cardNo: "", //卡号
        email: "", //邮箱
        mobile: "", //电话
        idCard: "", //身份证
        ymOrgTreeCode: "", //组织编号
        passPassword: "", //通行密码
        property: "1", //人员性质
        contacts: [], //联系人
      },
      formlists: {
        ymOrgTreeCode: "002",
        infoType: 1,
        status: "-1",
        vChild: true,
        key: "",
        page: 1,
        start: 0,
        limit: 5,
      },
      total: 0, //数据总数
      labelCol: { span: 8 },
      wrapperCol: { span: 14 },
      ids: "",
      isok: true,
      idsts: "",
      selectflist: {
        ymOrgTreeCode: "", //组织编号
        ymorgId: "", //组织id
        infoid: "", //人员id
      },
      filex: "",
      file: null,
      dictionariesA: [],
      dictionariesB: [],
      parms: "",
    };
  },
  created() {
    this._getPerages();
    this._getdiction();
    this.parms = Setperms(
      this.$route.fullPath,
      JSON.parse(sessionStorage.getItem("menu"))
    );
    console.log(this.parms);
  },
  methods: {
    isTrue(str) {
      return this.parms.indexOf(str) !== -1;
    },
    _getdiction() {
      getdiction({ params: this.fromdic }).then((res) => {
        this.dictionariesA = res.data.data;
      });
      getdiction({ params: this.fromdicB }).then((res) => {
        this.dictionariesB = res.data.data;
      });
    },
    newMember() {
      this.form.contacts.push({
        linkman: "",
        linkmobile: "",
        linkdes: "",
        id: 0,
        stafforstudinfoid: this.form.id,
        isNew: true,
      });
    },
    // 请求菜单数据
    _getPerages() {

      getPerages({ params: this.forpupdata })
        .then((res) => {
          if (res.data) {
            this.items = res.data;
            this.$message.success("获取员工数据成功");
            this._chexd();
          }
        }).catch((err) => {
        // this.$message.error("获取员工数据失败");
      });
    },
    // 选中tree数据执行
    checked(value, label, extra) {
      //判断是否选中值了
      if (extra.triggerNode) {
        //获取当前选中的对象信息
        const cont = extra.triggerNode.$attrs.cont;
        this.form.ymOrgId = cont.id;
        this.form.ymOrgTreeCode = cont.ymorgtreecode;
        this.formlists.ymOrgTreeCode = cont.ymorgtreecode;
        this._getStaff();
      }
    },
    //有效按钮的点击
    chxedsd(scope, doc, i) {
      this.ids = doc;
      this.$refs.unpchxed.showModal();
    },
    //有效弹窗确定按钮
    unpchxed() {
      if (this.ids.status == 0) {
        getStudInfo({ ids: this.ids.id }).then((res) => {
          this._getStaff();
        });
      } else {
        getDisabled({ ids: this.ids.id }).then((res) => {
          this._getStaff();
        });
      }
      this.$refs.unpchxed.handleCancel();
    },
    //修改弹窗点击
    changed(text, tags, i) {

      this.disableds = true;

      console.log(tags);
      this.isok = true;
      this.modals.title = this.$t("m.ModifyEmployeeInformation");
      this.form.id = tags.id;
      this.form.staffOrStuCode = tags.stafforstucode;
      this.form.staffOrStuName = tags.stafforstuname; //人员名称
      this.form.sex = tags.sex == "男" ? "1" : "2"; //性别
      this.form.nation = tags.nation; //民族
      this.form.birthday = tags.birthday; //生日
      this.form.address = tags.address; //地址
      this.form.startDate = tags.startdate; //开始地址
      this.form.endDate = tags.enddate; //结束日期
      this.form.cardNo = tags.cardno; //卡号
      this.form.email = tags.email; //邮箱
      this.form.mobile = tags.mobile; //电话
      this.form.idCard = tags.idcard; //身份证
      this.form.ymOrgTreeCode = tags.ymorgtreecode; //组织编号
      this.form.passPassword = tags.passpassword; //通行密码
      this.form.property = String(tags.property); //人员性质
      this.form.contacts = []; //联系人
      this.idsts = tags.id;
      this.idst = tags.ymorgid;
      getCustContactsList({ params: { staffOrStudInfoId: tags.id } }).then(
        (res) => {
          this.form.contacts = res.data.data.map((item) => {
            return {
              id: item.id,
              linkdes: item.linkdes,
              linkman: item.linkman,
              linkmobile: item.linkmobile,
              stafforstudinfoid: item.stafforstudinfoid,
            };
          });
        }
      );
      this.modals.visible = true;
    },
    //修改弹窗取消
    modalhand() {
      this.$refs.ruleForm.resetFields();
      this.clearContents();
    },
    // 默认展示数据
    _chexd() {
      //默认选择第一条数据
      const item = this.items[0];
      this.form.ymOrgId = item.id;
      this.form.ymOrgTreeCode = item.ymorgtreecode;
      this.formlists.ymOrgTreeCode = item.ymorgtreecode;
      // this.formlists.status = item.status;
      this.value = item.custorgname;
      this._getStaff();
    },
    //修改弹窗确定
    changedup() {
      getSaveStudent(this.form).then((res) => {
        const msg = res.data.msg;
        this.form.id = 0;
        if (res.data.success) {
          this.$message.success("修改人员信息成功");
          this._getStaff();
        } else {``
          this.$message.error("修改人员信息失败");
        }
        this.clearContents();
        this.modal.visible = false;
      });
    },
    //删除按钮点击
    pupildelete(text, tags, i) {
      this.deleteId = tags.id;
      this.$refs.unpdelete.showModal();
    },
    //删除事件
    unpdelete() {
      getDelStudentInfo({ id: this.deleteId }).then((res) => {
        const msg = res.data.msg;
        if (res.data.success) {
          this.$message.success(msg);
          this._getStaff();
        } else {
          this.$message.error(msg);
        }
        this.$refs.unpdelete.handleCancel();
      });
    },
    //搜索点击
    pupSearch() {
      this._chexd();
      this.value = "";
    },

    // 新增
    addRess() {
      this.disableds = false;
      this.isok = false;
      this.form.sex = "1";
      this.form.property = "1";
      this.modals.title = "新增职工信息";
      this.modals.visible = true;
      this.form.id = 0;
    },
    //请求列表数据
    _getStaff() {
      getStaff({ params: this.formlists }).then((res) => {
        this.total = res.data.total;
        console.log(res.data);
        res.data.data.forEach((item, index) => {
          if (item.sex == 1) {
            res.data.data[index].sex = "男";
          } else {
            res.data.data[index].sex = "女";
          }
        });
        this.datas = res.data.data;
      });
    },
    //确定按钮的点击
    editLodemo() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.form.contacts = JSON.stringify(this.form.contacts);
          getSaveStudent(this.form)
            .then((res) => {
              const msg = res.data.msg;
              if (res.data.success) {
                this.$message.success("修改员工信息成功");
                this._getStaff();
              } else {
                this.$message.error("修改员工信息失败");
              }
            })
            .catch((err) => {
              this.$message.error("数据保存失败");
            });
          this.clearContents();
          this.modals.visible = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //清除表单数据
    clearContents() {
      this.form.staffOrStuCode = "";
      this.form.staffOrStuName = ""; //人员名称
      this.form.sex = ""; //性别
      this.form.nation = ""; //民族
      this.form.birthday = ""; //生日
      this.form.address = ""; //地址
      this.form.startDate = ""; //开始地址
      this.form.endDate = ""; //结束日期
      this.form.cardNo = ""; //卡号
      this.form.email = ""; //邮箱
      this.form.mobile = ""; //电话
      this.form.idCard = ""; //身份证
      // this.form.ymOrgTreeCode = ""; //组织编号
      this.form.passPassword = ""; //通行密码
      this.form.property = ""; //人员性质
      this.form.contacts = []; //联系人
    },
    //选择有效或者无效
    handleSelectChange() {
      this._getStaff();
    },
    //是否显示子节点
    textChange() {
      this.formlists.vChild = !this.formlists.vChild;
      this._getStaff();
    },
    //更多
    //调整班级
    eadjustment(text, tags, i) {
      this.selectflist.infoid = tags.id;
      this.eadjust.visible = true;
    },
    // 选中班级获取数据
    selectlist(selectedKeys, idNode) {
      const idNodes = idNode.selectedNodes[0].data.props.dataRef;
      console.log(idNodes);
      this.selectflist.ymOrgTreeCode = idNodes.ymorgtreecode;
      this.selectflist.ymorgId = idNodes.id;
    },
    //调整班级确定
    eadjustup() {
      console.log(1);
      getMoveStaffInfo(this.selectflist).then((res) => {
        const msg = res.data.msg;
        if (res.data.success) {
          this.$message.success(msg);
          this._getStaff();
        } else {
          this.$message.error(msg);
        }
      });
      this.eadjust.visible = false;
    },
    //调整班级取消 清空数据
    eadjusthand() {
      this.selectflist.ymorgId = "";
      this.selectflist.ymOrgTreeCode = "";
      this.selectflist.ymorgId = "";
      this.eadjust.visible = false;
    },
    //保存读头
    contvmo(text, tags, i) {
      console.log(text, tags, i);
      this.form.contacts[i].isNew = false;
    },
    //修改读头
    contvmos(text, tags, i) {
      console.log(i);
      //渲染新数据
      this.$set(this.form.contacts[i], "isNew", true);
    },
    //删除读头
    deletevmos(text, tags, i) {
      console.log(tags);
      if (this.isok) {
        delCustContacts({ contactsId: tags.id }).then((res) => {
          this.$message.success("删除成功");
          getCustContactsList({
            params: { staffOrStudInfoId: this.idsts },
          }).then((res) => {
            this.form.contacts = res.data.data;
          });
        });
      }
      if (!this.isok) {
        this.form.contacts.splice(i, 1);
      }
    },
    //导入excel
    beforeUpload(file) {
      const num = file.name.indexOf(".");
      const xls = file.name.slice(num, 20);
      if (xls == ".xls" || xls == ".xlsx") {
        this.filex = file.name;
        this.file = file;
      } else {
        this.$message.error("请上传excel文件");
        return false;
      }
    },
    //导入档案
    importEdit() {
      this.imports.visible = true;
    },
    //覆盖默认上传
    cover() {},
    //导入档案确定
    importsup() {
      const data = new FormData();
      data.append("infoType", "1");
      data.append("excelfile", this.file);
      const upload_ax = axios.create({
        baseURL: "/api", //在vite.config.js配置的跨域
        withCredentials: true, //上传请求时是否携带 cookie
        headers: {
          "Content-Type": "multipart/form-data",
        },
      });
      upload_ax.post("/StaffOrStudInfo/importInfo", data).then((res) => {
        console.log(res);
        const msg = res.data.msg;
        if (res.data.success) {
          this.$message.success(msg);
        } else if (res.data.msg == null) {
        } else {
          this.$message.error(msg);
        }
      });
      this.imports.visible = false;
      this.file = null;
      this.filex = "";
    },
    //导入档案取消
    importshand() {
      this.imports.visible = false;
      this.file = null;
      this.filex = "";
    },
    //导出档案
    exportEdit() {
      exportInfo(this.formlists).then((res) => {
        console.log(res);
        let elink = document.createElement("a");
        // 设置下载文件名
        // const url = "http://ymapi.ymiots.com/";
        const url = window.location.origin;
        const link = res.data.msg;
        elink.download = res.data.msg;
        elink.style.display = "none";
        elink.href = nework + "/" + link;
        document.body.appendChild(elink);
        elink.click();
        document.body.removeChild(elink);
      });
    },
    onContextMenuClick(treeKey, menuKey) {
      console.log(`treeKey: ${treeKey}, menuKey: ${menuKey}`);
    },
    //分页事件
    upilPages(page, limit) {
      console.log(page, limit);
      this.formlists.page = page;
      this.formlists.limit = limit;
      this.formlists.start = (page - 1) * limit;
      this._getStaff();
    },
    onShowupilChange(page, pageSize) {
      this.formlists.page = page;
      this.formlists.limit = pageSize;
      this.formlists.start = (page - 1) * pageSize;
      this._getStaff();
    },
    //表单日历时间转换
    DateonChangeA(date, dateString) {
      this.form.startDate = dateString;
    },
    DateonChangeB(date, dateString) {
      this.form.endDate = dateString;
    },
    DateonChangeC(date, dateString) {
      this.form.birthday = dateString;
    },
    //下载模板
    addexcel() {
      getExportExcelTemplate().then((res) => {
        console.log(res);
        let blob = new Blob([res]);
        if ("msSaveOrOpenBlob" in navigator) {
          window.navigator.msSaveOrOpenBlob(blob, res.data.msg);
        } else {
          let elink = document.createElement("a");
          // 设置下载文件名
          const url = "http://ymapi.ymiots.com/";
          const link = res.data.msg;
          console.log(URL.createObjectURL(blob));
          elink.download = res.data.msg;
          elink.style.display = "none";
           elink.href = nework + "/" + link;

          document.body.appendChild(elink);
          elink.click();
          document.body.removeChild(elink);
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
.search {
  display: flex;
  height: 35px;

  .search-a {
    width: 300px;
    height: 35px;
  }
  .ov_flex {
    display: flex;
    align-items: center;
  }
  /deep/ .ant-select-selection {
    height: 35px;
  }
  /deep/ .ant-select-selection__rendered {
    line-height: 35px;
  }
  .btns {
    display: flex;
    flex-wrap: nowrap;
  }
  /deep/ .ant-select-allow-clear {
    margin-left: 15px !important;
  }
}
.input-a {
  margin-left: 15px;
  height: 35px;
}
/deep/ .ant-input-affix-wrapper .ant-input {
  height: 35px;
}
/deep/ .ant-input-lg {
  font-size: 14px;
}
.btn {
  width: 73px;
  font-size: 10px;
  margin-left: 10px;
}
.conter-table {
  margin-top: 30px;
}
.set-time {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.ant-form-item {
  width: 400px;
}
.pages {
  text-align: end;
  margin-top: 20px;
}
.select-a {
  width: 120px;
  margin-right: 15px;
}
.chend {
  line-height: 35px;
  margin-left: 15px;
}
.form-modak {
  display: flex;
}
/deep/ .ant-calendar-picker {
  width: 100%;
}
.mobles p{
  line-height: 32px;
}
</style>
